<%@ page import="com.cindata.NumberUtil" %>
<!DOCTYPE html>
<html>
<head>
    <meta name="layout" content="main"/>
    <g:set var="entityName" value="${message(code: 'estate.label', default: 'estate')}"/>
    <title>开发商查询</title>
    <style>
    .table>tbody>tr>td{
        vertical-align: middle;
    }
    #word>a{
        border-radius: 0!important;
    }
    #searchCondition{
        border-radius: 0!important;
    }
    </style>
</head>

<body class="fixed-navbar fixed-sidebar">
<div class="landing-page">
    <div class="small-header">
        <div class="hpanel">
            <div class="panel-body">
                <div id="hbreadcrumb" class="pull-right">
                    <ol class="hbreadcrumb breadcrumb">
                        <li>CINDATA PLS</li>
                        <li>新盘准入</li>
                        <li class="active">
                            <span>开发商查询</span>
                        </li>
                    </ol>
                </div>

                <h2 class="font-light m-b-xs">
                    开发商查询
                </h2>
            </div>
        </div>
    </div>

    <header id="page-top">
        <div class="container">
            <div class="heading">
                <h1>
                    房地产开发商企业数据
                </h1>
                <span>Real estate developers big data</span>
                <p class="small">
                    整合公开的房地产开发商基本信息、项目信息、负面信息、企业关系、主要人员信息等，作为开发商和楼盘准入依据。
                </p>
                <g:form method="POST" action="" class="form-horizontal" role="form" id="form" onkeydown="if(event.keyCode==13) return false">
                    <div class="panel-body">
                        <div class="row">
                            %{--<div class="form-group col-sm-2" style="margin:0;">--}%
                            %{--<label class="col-sm-3 control-label">城市</label>--}%
                            %{--<g:select class="form-control" name="city" id="city"--}%
                            %{--from="${com.cindata.City.findAll("from City order by convert_to(name, 'gbk')")}"--}%
                            %{--valueMessagePrefix="status" optionKey="zoneNumber" optionValue="name"--}%
                            %{--value="${params?.city}"/>--}%
                            %{--</div>--}%

                            <div class="form-group col-sm-6 col-sm-offset-1">
                                <input type="text" class="form-control" name="searchCondition" id="searchCondition"
                                       value="${params?.searchCondition}" placeholder="请输入开发商名称">
                                <div id="word"></div>
                            </div>
                        </div>
                    </div>
                </g:form>
            </div>

        </div>
    </header>
</div>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>

    $(function () {
        var tempkey = "";
        //当键盘键被松开时发送Ajax获取数据
        $('#searchCondition').keyup(function () {
            console.log("触发")
            var keywords = $(this).val();
            //var city = $('#city').val()
            if (keywords == '') {
                $('#word').hide();
                return
            }
            //还是要减少下请求次数的
            if (tempkey == keywords){
                return
            }else{
                tempkey =  keywords
            }
            setTimeout(function(){
                if(keywords!=$('#searchCondition').val()){
                    return
                }
                $.ajax({
                        url: '/developer/searchCompany',
                        data: {
                            keywords: keywords
                        },
                        dataType: 'json',
                        //jsonp: 'cb', //回调函数的参数名(键值)key
                        // jsonpCallback: 'fun', //回调函数名(值) value
                        beforeSend: function () {
                            $('#word').append('<div class="form-control">正在加载。。。</div>');
                        },
                        success: function (parameter) {
                            $('#word').empty().show();
                            if (parameter.s == '' || parameter.s == null) {
                                $('#word').append('<div class="error form-control">未找到  "' + keywords + '"</div>');
                            }
                            var i = -1;
                            $.each(parameter.s, function () {
                                i++;
//                        $('#word').append('<div class="click_work form-control">' + this + '</div>');
                                console.log(parameter)
                                $('#word').append('<a href="detailn?companyId='+parameter.id[i]+'&companyName='+this+'"   data-city="'+parameter.city+'" data-cid = "' + parameter.id[i] + '" class="click_work form-control">' + this + '</a>');
                            })
                        },
                        error: function () {
                            $('#word').empty().show();
                            $('#word').append('<div class="form-control">Fail "' + keywords + '"</div>');
                        }
                    })
            },300);

        })
        //点击搜索数据复制给搜索框
//        $(document).on('click', '.click_work', function () {
//            var word = $(this).text();
//            $('#searchCondition').val(word);
//            $('#word').hide();
//            // $('#texe').trigger('click');触发搜索事件
//        })
    })
</script>
</body>
</html>
